// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.chimi.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarPlateReq;
import com.liuxinlong.modules.chimi.service.BarPlateService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.BaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.BarPlate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 论坛板块管理控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/plate")
public class BarPlateController {
	@Autowired
	private BarPlateService barPlateService;

	/**
	 * 分页查询板块信息
	 * 
	 * @param req 请求信息
	 * @return 板块信息列表
	 */
	@PostMapping("page")
//	@LogAnnotation(value ="分页查询",business = LogBusinessConstants.BAR_PLATE,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp pagePlateInfo(@RequestBody BaseReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",req.getPageSize());
		List<Map<String,Object>> dataList = barPlateService.pagePlate(queryParam);
		int total = barPlateService.getPlateCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询板块信息成功");
		return resp;
	}

	/**
	 * 新增板块
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("add")
	@LogAnnotation(value ="新增板块",business = LogBusinessConstants.BAR_PLATE,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp addPlate(@RequestBody UpdateBarPlateReq req) {
		BarPlate barPlate = new BarPlate();
		barPlate.setName(req.getName());
		barPlate.setSortNum(req.getSortNum());
		barPlate.setPicture(req.getPicture());
		barPlate.setStatus(req.getStatus());
		barPlateService.addPlate(barPlate);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("新增板块成功");
		return resp;
	}

	/**
	 * 修改板块信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("update")
	@LogAnnotation(value ="修改板块信息",business = LogBusinessConstants.BAR_PLATE,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updatePlate(@RequestBody UpdateBarPlateReq req) {
		BarPlate barPlate = new BarPlate();
		barPlate.setId(req.getId());
		barPlate.setName(req.getName());
		barPlate.setSortNum(req.getSortNum());
		barPlate.setPicture(req.getPicture());
		barPlate.setStatus(req.getStatus());
		barPlateService.updatePlate(barPlate);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改板块信息成功");
		return resp;
	}

	/**
	 * 删除板块信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("delete")
	@LogAnnotation(value ="删除板块信息",business = LogBusinessConstants.BAR_PLATE,operateType = LogOperateConstants.OPERATE_DELETE)
	public BaseResp deletePlate(@RequestBody BaseDeleteReq req) {
		barPlateService.deletePlate(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("删除板块信息成功");
		return resp;
	}

}
